#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@File    ：ppCar_city.py
@Author  ：Juff
@Date    ：2023/10/14 11:19 
'''


# 爬取所有城市名称
from selenium import webdriver
from selenium.webdriver.common.by import By

fp = open('./city.txt',"w",encoding='utf-8')

driver = webdriver.Edge()
driver.get("https://www.renrenche.com/hf/ershouche/")

div_list = driver.find_elements(By.XPATH,"//div[@class='area-city-letter']/div")
for div in div_list:
    a_list = div.find_elements(By.XPATH,"a")
    for a in a_list:
        city_jx = a.get_attribute("rrc-event-name")
        city_name = a.get_attribute("rrc-event-expand-tag_value")
        fp.write(city_jx+"@"+city_name+"\n")

driver.close()